package Arrays;

import java.util.Arrays;

public class _414_ThirdMaximumNumber {

    //the question context is when there are some numbers have the same value,they have the same rank,
    //example:1,2,2,3,the third maximum value is 1
    public int thirdMax(int[] nums) {
        int count = 1;
        Arrays.sort(nums);
        //don't think about the quality of the number
        for(int i=nums.length-1;i>0;i--) {
            if (nums[i] != nums[i - 1]) {
                count++;
            }
            if (count == 3) {
                return nums[i-1];
            }
        }
        return nums[nums.length-1];
        //think about the quality of the number
        /*if (nums.length < 3) {
            return nums[nums.length - 1];
        } else {
            return nums[nums.length-3];
        }*/
    }
}
